import { Component, OnInit } from '@angular/core';
import {ActivatedRoute} from "@angular/router";
import {ResponseUtil} from "../../../../util/response-util";
import {OneDialogService} from "../../../../widgets/one-dialog/one-dialog.service";
import {MsgResult} from "../../../../models/msg-result";
import {MsgConstants} from "../../../../constants/constants";
import {LoginService} from "../login.service";
import {Login} from "../login";

@Component({
  selector: 'app-login-detail',
  templateUrl: './login-detail.component.html',
  styleUrls: ['./login-detail.component.css']
})
export class LoginDetailComponent implements OnInit {

    loginLog : Login;

    constructor(
      private route:ActivatedRoute,
      private responseUtil : ResponseUtil,
      private dialogService: OneDialogService,
      private loginService : LoginService
  ) {
      this.initLoginObj();
    }

    ngOnInit() {
      this.getLoginLogDetail();
    }

    getLoginLogDetail(){
      let id = this.route.snapshot.params['id'];
      this.loginService.loginLogDetails(id).subscribe(
        result => this.responseUtil.success(result,this.processLoginLogResult),
        error => this.responseUtil.error(error)
      );
    }

  private processLoginLogResult =(result:MsgResult)=>{
      if(result && result.code == MsgConstants.MSG_CODE_OK){
        this.loginLog = result.data;
      }
      if(result && result.code != MsgConstants.MSG_CODE_OK){
        this.dialogService.error(result.message);
      }
    }

    initLoginObj(){
      this.loginLog = new Login;
    }
}
